package com.housekeeping.housekeeping.usermanagement.dao.impl;

import com.housekeeping.housekeeping.usermanagement.entity.InformationUser;
import com.housekeeping.housekeeping.usermanagement.utils.DBManager;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/*
* 对数据库插入
* */
public class InsertDao extends OperationDaoImpl {

    @Override
    public int insert(InformationUser information) throws SQLException {
        Connection connection= DBManager.getConnection();
        String sql="insert into order_user(name,phone,wechat,datetime) value(?,?,?,?)";
        PreparedStatement preparedStatement=connection.prepareStatement(sql);
        preparedStatement.setString(1,information.getName());
        preparedStatement.setString(2,information.getPhone());
        preparedStatement.setString(3,information.getWechat());
        preparedStatement.setDate(4, Date.valueOf(information.getDatetime()));
        int i = preparedStatement.executeUpdate();
        DBManager.close(connection,preparedStatement);
        return i;
    }
}
